#! /bin/bash

#创建dw层
echo 'create dw layout data table.....'
#hive -f createdwdinit.sql

echo 'import data.....'
#hive -f loaddata.sql


echo 'generator date data.....'
num=0
while(( $num<=360 ))
do
  dt=`date -d "20180101 ${num} day" "+%Y-%m-%d"`
  mtname=`date -d "${dt}" "+%B"`
  mt=`date -d "${dt}" "+%m"`
  if  [ $mt -le 3 ]
  then
     qt=1
  elif [ $mt -le 6 ]
  then
     qt=2
  elif [ $mt -le 9 ]
  then
     qt=3
  else
      qt=4
   fi
  let num=$num+1
  hive -e  "insert into dw_sales_source.dwd_dim_date values($num,$dt,$mt,$mtname,$qt,${dt:0:4})"
done

echo 'import fact table.....'

hive -e 'insert into dw_sales_source.dwd_fact_sales_order
select 
oso.order_number as order_sk,
oso.customer_number as customer_sk,
oso.product_code as product_sk,
dss.date_sk,
oso.order_amount 
from ods_sales_source.ods_dynmic_sales_order oso inner join dw_sales_source.dwd_dim_date dss
on oso.order_date=dss.d_date'